#ifndef _COMM_H_
#define _COMM_H_

#include <iostream>
#include <cstdio>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <cassert>
#include <string.h>
#include <fcntl.h>
#include "log.hpp"

using namespace std; //不推荐

#define PATH_NAME "/home/dgz"
#define PROJ_ID 0x66
#define SHM_SIZE 4096 //共享内存的大小，最好是页(PAGE: 4096)的整数倍 
#define FIFO_NAME "./fifo"
#define READ O_RDONLY
#define WRITE O_WRONLY
class Init
{
public:
    
    Init()
    {
        umask(0);
        int s = mkfifo(FIFO_NAME,0666);
        assert(s != -1);
        (void)s;
        log("创建管道文件成功",DEBUG) << endl;
    }
    ~Init()
    {
        unlink(FIFO_NAME);
        log("移除管道文件成功",DEBUG) << endl;
    }

};

int OpenFIFO(string pathname,int flags)
{
    int fd = open(pathname.c_str(),flags);
    assert(fd >= 0);
    return fd;
}

void wait(int fd)
{
    log("等待中....",DEBUG) << endl;
    uint32_t tmp = 0;
    ssize_t s = read(fd,&tmp,sizeof(uint32_t));
    assert(s == sizeof (uint32_t));
    (void)s;
}

void send(int fd)
{
    uint32_t tmp = 0;
    ssize_t s = write(fd,&tmp,sizeof(uint32_t));
    assert(s == sizeof (uint32_t));
    (void)s;
    log("唤醒中",DEBUG) << endl;
}

void closefd(int fd)
{
    close(fd);
}




#endif